//
//  ZXXEmoticonPageView.swift
//  M-Weibo
//
//  Created by ZXX on 16/4/25.
//  Copyright © 2016年 ZXX. All rights reserved.
//

import UIKit
///重用cell的标识符
let  ZXXEmoticonPictureViewCellReuseIdentifier = "ZXXEmoticonPictureViewCellReuseIdentifier"
class ZXXEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        //设置视图
        setupUI()
        
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //  MARK: -  设置视图
    private func setupUI(){
        backgroundColor = UIColor.whiteColor()
        dataSource = self
        //注册cell
        registerClass(ZXXEmoticonPictureViewCell.self, forCellWithReuseIdentifier:ZXXEmoticonPictureViewCellReuseIdentifier )
        
        // 设置layout
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        
        // 设置itemSize
        layout.itemSize = CGSize(width: SCREENWIDTH, height: EmoticonKeyboardHeight - EmoticonKeyboardToolBarHeight)
        
        // 设置垂直和水平间距
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        // 更改我们pageView 的滚动方向
        layout.scrollDirection = .Horizontal

    }
    
}
//  MARK: - UICollectionViewDataSource
extension ZXXEmoticonPageView: UICollectionViewDataSource{
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return ZXXEmoticonTools.sharedZXXEmoticonTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return ZXXEmoticonTools.sharedZXXEmoticonTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ZXXEmoticonPictureViewCellReuseIdentifier, forIndexPath: indexPath) as! ZXXEmoticonPictureViewCell
        cell.emoticons = ZXXEmoticonTools.sharedZXXEmoticonTools.allEmoticons[indexPath.section][indexPath.item]
        return cell
        
    }
}